package com.example.joke;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

import com.example.joke.base.http.EngineCallBack;
import com.example.joke.base.http.IHttpEngine;
import com.example.joke.base.http.OkhttpEngine;
import com.example.joke.proxy.Custom;
import com.example.joke.proxy.IOperate;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.HashMap;

public class o {
    private Direction mDirection;
    private enum Direction {
        LEFT_TO_RIGHT, RIGHT_TO_LEFT
    }

    public static Class<?> analysisClazzInfo(Object object){
        Type genType = object.getClass().getGenericSuperclass();
        Type[] params = ((ParameterizedType)genType).getActualTypeArguments();
        return (Class<?>) params[0];
    }

    public final EngineCallBack DEFAULT_CALL_BACK = new EngineCallBack() {
        @Override
        public void onPreExecute(@NonNull Context context, @NonNull HashMap<String, Object> params) {

        }

        @Override
        public void onError(@NonNull Exception e) {

        }

        @Override
        public void onSuccess(@NonNull String result) {

        }

    };
    public static IHttpEngine httpEngine = new OkhttpEngine();

    private o() {}

    public static o create() {
        Custom custom = new Custom();
        IOperate proxy = (IOperate) Proxy.newProxyInstance(
                IOperate.class.getClassLoader(),
                new Class<?>[]{IOperate.class},
                new BankInvocationHandler(custom)
        );
        proxy.makeCard();
        proxy.changePwd();
        return new o();
    }

    public static class BankInvocationHandler implements InvocationHandler {
        private IOperate custom;

        public BankInvocationHandler(IOperate custom) {
            this.custom = custom;
        }

        @Override
        public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
            Log.d("bank---Employee：", "办理业务前的准备工作") ;
            Object obj = method.invoke(custom, objects);
            Log.d("bank---Employee：", "业务办理完毕");
            return obj;
        }
    }
}
